package com.cvlep.mts.service;

import org.cometd.Bayeux;
import org.cometd.Client;
import org.cometd.Message;
import org.cometd.server.BayeuxService;

import com.cvlep.appbase.log.MTSLogger;

public class Monitor extends BayeuxService
{

	public Monitor(Bayeux bayeux)
	{
		super(bayeux, "monitor");
		subscribe("/meta/subscribe", "monitorSubscribe");
		subscribe("/meta/unsubscribe", "monitorUnsubscribe");
		subscribe("/meta/*", "monitorMeta");

	}

	public void monitorSubscribe(Client client, Message message)
	{
		MTSLogger.info("Subscribe from " + client + " for "
				+ message.get(Bayeux.SUBSCRIPTION_FIELD));
		
		System.out.println("Subscribe from " + client + " for "
				+ message.get(Bayeux.SUBSCRIPTION_FIELD));
	}

	public void monitorUnsubscribe(Client client, Message message)
	{
		MTSLogger.info("Unsubscribe from " + client + " for "
				+ message.get(Bayeux.SUBSCRIPTION_FIELD));
		System.out.println("Unsubscribe from " + client + " for "
				+ message.get(Bayeux.SUBSCRIPTION_FIELD));
	}

	public void monitorMeta(Client client, Message message)
	{
		MTSLogger.debug(message.toString());
		System.out.println(message.toString());
	}
}
